- /* sdmstdbl.cpp by K.Tsuru */
- // function ID = 303 DRADIX
- /******************************************************************
- SDouble class
- It sets a value by double, including long, etc.
- [caution]
- The usage such as
- SDouble x(SNumber::BIN_DEC, 0);
- x = 1.0;
- must be considered.See Dpow() for example.
- A statement
- x = 1.1; ... recurring decimal in the binary radix
- yields an error. It does not call the function of radix conversion.
- ********************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* const func = "SetDouble";
- void SDouble::SetDouble(double d){
- if(d == 0.0){
- if(RawSign()) SetZero();
- return; // d = 0, sign = 0
- }
- double absd = fabs(d), dp;
- fType ip;
- uint sz;
- if(Type() == BIN_DEC){
- rdxExp = 0;
- int f = doubleToBinDec(absd, figure, &sz);
- if(f < 0) SetError(OVERFLOW_ERR, func, 303);
- /*
- See above. When the number of figures is three over(45 bits), the probabirity
- of recurring decimal is strong.
- */
- else if(f >= 3) SetError(SYNTAX_ERR, func, 303);
- aTail = 0;
- sz = min(sz, SNMaxSize(BIN_DEC));
- while( (figure(aTail)== 0) && (aTail < sz) ) aTail++;
- //"d" is very small and practically equal to zero within the effective figures.
- if(aTail == sz){
- SetZero(); return;
- }
- aHead = sz-1u; while(figure(aHead)== 0) aHead--;
- goto Ret;
- }
- if(absd < (double)Radix()){ // abc.0
- ip = (fType)(absd + DBL_EPSILON);
- dp = fabs(absd - (double)ip);
- if(ip && dp < DBL_EPSILON){ //integral part!=0, decimal part==0
- if(RawSign()) SetZero();//including memory allocation
- aHead = aTail = 1;
- figure[1] = ip; rdxExp = 1;
- goto Ret;
- }
- }
- rdxExp = doubleToArray(absd, figure, &sz);
- #ifndef NDEBUG
- assert(figure(1)); // x != 0
- #endif
- aHead = sz-1; aTail = 1u;
- Ret:
- SetSign(d);
- Reform(303);
- }
sdmstdbl.cpp : last modifiled at 2017/04/10 20:34:42(1,878 bytes)
created at 2017/10/07 10:21:14
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).